package zsc.ruanc.practicaltraining.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import zsc.ruanc.practicaltraining.model.result.JsonResult;
import zsc.ruanc.practicaltraining.service.AuthorityService;
import zsc.ruanc.practicaltraining.utils.ResultUtils;

import javax.validation.constraints.Min;

/**
 * 权限控制器
 */
@RestController
@RequestMapping("/authority")
@Api(tags = "权限/角色模块")
public class AuthorityController {

    @Autowired
    private AuthorityService authorityService;

    @GetMapping("/selectRole")
    @ApiOperation(value = "获得所有角色", httpMethod = "GET")
    public JsonResult selectAllRole() {
        return ResultUtils.success(authorityService.role());
    }

    @GetMapping("/selectUrl")
    @ApiOperation(value = "获取后端接口的url（分页）", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cur", value = "当前页", dataType = "Integer", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "页大小", dataType = "Integer", paramType = "query", defaultValue = "10")
    })
    public JsonResult selectUrl(@Min(message = "参数cur不能小于0", value = 0) @RequestParam(value = "cur", defaultValue = "1") Integer cur,
                                @Min(message = "参数size不能小于1", value = 1) @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return ResultUtils.success(authorityService.url(cur, size));
    }


}
